#ifndef __PAY_BOX_H__
#define __PAY_BOX_H__

#include <Arduino.h>

//按钮输入
#define PAY_KEY_RESET GPIO_NUM_5
#define PAY_KEY_ON GPIO_NUM_34
#define PAY_KEY_ADD GPIO_NUM_39
#define PAY_KEY_MINUS GPIO_NUM_36
#define PAY_KEY_REFRESH GPIO_NUM_35

// LED输出
#define PAY_LED_RED GPIO_NUM_4
#define PAY_LED_GREEN GPIO_NUM_33
#define PAY_LED_BLUE GPIO_NUM_13

//音频数字输出
#define PAY_AUDIO_SDATA GPIO_NUM_14
#define PAY_AUDIO_SCLK GPIO_NUM_26
#define PAY_AUDIO_LRCK GPIO_NUM_27
#define PAY_AUDIO_CLKIN GPIO_NUM_0
#define PAY_AUDIO_CTRL GPIO_NUM_2

// TFT输出
#define PAY_TFT_BAK GPIO_NUM_15
#define PAY_TFT_CS GPIO_NUM_22
#define PAY_TFT_MOSI GPIO_NUM_23
#define PAY_TFT_SCLK GPIO_NUM_19
#define PAY_TFT_DC GPIO_NUM_21
#define PAY_TFT_RST GPIO_NUM_18
#define PAY_TFT_MISO GPIO_NUM_25

#include "PayLED.h"
#include "PayTFT.h"
#include <WiFi.h>

void inline bindKeyEvent(int pin, void (*intRoutine)()) {
  pinMode(pin, INPUT_PULLUP);
  attachInterrupt(digitalPinToInterrupt(pin), intRoutine, FALLING);
}

// 通过AutoConfig配置Wifi热点
void autoConfigWifi() {
  WiFi.mode(WIFI_MODE_STA);
  WiFi.begin();
  for (int i = 0; WiFi.status() != WL_CONNECTED && i < 100; i++) {
    delay(100);
  }
  if (WiFi.status() != WL_CONNECTED) {
    WiFi.mode(WIFI_MODE_APSTA);
    WiFi.beginSmartConfig();
    while (WiFi.status() != WL_CONNECTED) {
      delay(100);
    }
    WiFi.stopSmartConfig();
    WiFi.mode(WIFI_MODE_STA);
  }
}

#endif
